package ExtendDemo.demo12;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.UUID;

public class ServerDemo {
    public static void main(String[] args)  throws IOException {
        ServerSocket ss = new ServerSocket(10004);
        Socket s = ss.accept();

        InputStream is = s.getInputStream();

        BufferedInputStream bis=new BufferedInputStream(is);
        BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(UUID.randomUUID().toString()+".jpg"));
        int len;
        while ((len= bis.read())!=-1){
            bos.write(len);
        }
        BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
        bw.write("上传成功");
        bw.newLine();
        bw.flush();

        bos.close();
        s.close();
        ss.close();
    }
}
